//
//  ChangePhoneNumViewController.m
//  联付商圈
//
//  Created by 韩佳睿 on 2017/8/15.
//  Copyright © 2017年 lianfu. All rights reserved.
//

#import "ChangePhoneNumViewController.h"

@interface ChangePhoneNumViewController ()

@end

@implementation ChangePhoneNumViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self prepareNavBar];
}

- (void)prepareNavBar{
    self.navigationController.navigationBar.hidden = NO;
    self.navigationItem.title = @"更换手机号";
}

- (IBAction)sendSMSCode:(id)sender {
    
}

- (IBAction)finishBtnAction:(id)sender {
    NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"];
    SQUserModel *model = [SQUserModel yy_modelWithDictionary:dic];
    
    NSDictionary *param = @{@"name" : model.userName};
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain", nil];
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    [manager GET:[Host stringByAppendingString:@"payword?"] parameters:param progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        if (dic[@"success"]) {
            
            MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
            HUD.labelText = dic[@"success"][@"message"];
            HUD.mode = MBProgressHUDModeText;
            [HUD hide:YES afterDelay:1.0];
        } else {
            MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:KeyWindow animated:YES];
            HUD.labelText = dic[@"error"][@"message"];
            HUD.mode = MBProgressHUDModeText;
            [HUD hide:YES afterDelay:1.0];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}

@end
